{% extends "base.html" %}

{% block content %}
<div class="container-fluid">
    <!-- 查询表单 -->
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="mb-0"><i class="fas fa-search me-2"></i>查询条件</h5>
        </div>
        <div class="card-body">
            <form method="GET" action="{{ url_for('network.network_index') }}" class="row g-3">
                <div class="col-md-4">
                    <label for="name" class="form-label">管网名称</label>
                    <input type="text" class="form-control" id="name" name="name" value="{{ search_name }}">
                </div>
                <div class="col-md-4">
                    <label for="pipe_type" class="form-label">管道类型</label>
                    <select class="form-select" id="pipe_type" name="pipe_type">
                        <option value="">全部</option>
                        <option value="main" {% if search_type == 'main' %}selected{% endif %}>主管</option>
                        <option value="branch" {% if search_type == 'branch' %}selected{% endif %}>支管</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <label for="status" class="form-label">状态</label>
                    <select class="form-select" id="status" name="status">
                        <option value="">全部</option>
                        <option value="normal" {% if search_status == 'normal' %}selected{% endif %}>正常</option>
                        <option value="maintenance" {% if search_status == 'maintenance' %}selected{% endif %}>维修中</option>
                        <option value="scrapped" {% if search_status == 'scrapped' %}selected{% endif %}>已报废</option>
                    </select>
                </div>
                <div class="col-12">
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-search me-1"></i>查询
                    </button>
                    <a href="{{ url_for('network.network_index') }}" class="btn btn-secondary">
                        <i class="fas fa-redo me-1"></i>重置
                    </a>
                    <a href="{{ url_for('network.network_add') }}" class="btn btn-success float-end">
                        <i class="fas fa-plus me-1"></i>添加管网
                    </a>
                </div>
            </form>
        </div>
    </div>

    <!-- 管网列表 -->
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0"><i class="fas fa-project-diagram me-2"></i>管网列表</h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>名称</th>
                            <th>类型</th>
                            <th>材质</th>
                            <th>管径(mm)</th>
                            <th>长度(m)</th>
                            <th>起点</th>
                            <th>终点</th>
                            <th>安装日期</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for pipe in pipes %}
                        <tr>
                            <td>{{ pipe.name }}</td>
                            <td>
                                {% if pipe.pipe_type == 'main' %}主管
                                {% elif pipe.pipe_type == 'branch' %}支管
                                {% else %}{{ pipe.pipe_type }}{% endif %}
                            </td>
                            <td>{{ pipe.material }}</td>
                            <td>{{ "%.1f"|format(pipe.diameter) }}</td>
                            <td>{{ "%.1f"|format(pipe.length) }}</td>
                            <td>{{ pipe.start_point }}</td>
                            <td>{{ pipe.end_point }}</td>
                            <td>{{ pipe.installation_date.strftime('%Y-%m-%d') }}</td>
                            <td>
                                <span class="badge {% if pipe.status == 'normal' %}bg-success
                                    {% elif pipe.status == 'maintenance' %}bg-warning
                                    {% else %}bg-danger{% endif %}">
                                    {% if pipe.status == 'normal' %}正常
                                    {% elif pipe.status == 'maintenance' %}维修中
                                    {% elif pipe.status == 'scrapped' %}已报废
                                    {% else %}{{ pipe.status }}{% endif %}
                                </span>
                            </td>
                            <td>
                                <a href="{{ url_for('network.network_edit', id=pipe.id) }}" class="btn btn-sm btn-primary">
                                    <i class="fas fa-edit me-1"></i>编辑
                                </a>
                                <a href="{{ url_for('network.maintenance_add', pipe_id=pipe.id) }}" class="btn btn-sm btn-warning">
                                    <i class="fas fa-tools me-1"></i>维护
                                </a>
                                <a href="{{ url_for('network.maintenance_history', pipe_id=pipe.id) }}" class="btn btn-sm btn-info">
                                    <i class="fas fa-history me-1"></i>记录
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            {% if pagination and pagination.pages > 1 %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    <li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('network.network_index', page=pagination.prev_num, name=search_name, pipe_type=search_type, status=search_status) if pagination.has_prev else '#' }}">
                            <i class="fas fa-chevron-left"></i>
                        </a>
                    </li>
                    {% for page in pagination.iter_pages() %}
                        {% if page %}
                            <li class="page-item {% if page == pagination.page %}active{% endif %}">
                                <a class="page-link" href="{{ url_for('network.network_index', page=page, name=search_name, pipe_type=search_type, status=search_status) }}">{{ page }}</a>
                            </li>
                        {% else %}
                            <li class="page-item disabled">
                                <span class="page-link">...</span>
                            </li>
                        {% endif %}
                    {% endfor %}
                    <li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('network.network_index', page=pagination.next_num, name=search_name, pipe_type=search_type, status=search_status) if pagination.has_next else '#' }}">
                            <i class="fas fa-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 